package com.itheima.mq;

import com.itheima.pojo.Order;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderService;
import com.itheima.service.OrderSettingService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class IsSuceesConsumer {

    @Resource
    private OrderService orderService;

    @Resource
    private OrderSettingService orderSettingService;

    @RabbitListener(queues = "dlxQu")
    public void isSuccess(String orderNo){
         //Integer status = orderService.selStatus(orderNo);
        Order order = orderService.findByOrderNo(orderNo);
        if (order.getPayStatus()==0){
             orderService.deleteByOrderNo(orderNo);
            OrderSetting orderSetting = orderSettingService.findByDate(order.getOrderDate());
            orderSetting.setReservations(orderSetting.getReservations()-1);
            orderSettingService.updateReservations(orderSetting);
        }
    }
}
